﻿@using SDF.Services
@using SDF.Plugin.Misc.DynamicEntity.Domain.Enums
@using SDF.Plugin.Misc.DynamicEntity.Extensions

@model  SDF.Plugin.Misc.DynamicEntity.Models.DynamicEntityItemModel

@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)

<script>
    $(document).ready(function () {
        bindBootstrapTabSelectEvent('fieldInfo-edit');
    });
</script>

<div class="content">
    <div class="form-horizontal">
        <div id="category-edit" class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                @Html.RenderBootstrapTabHeader("tab-info", @T("Plugins.Misc.DynamicEntity.ItemInfo"), true)
                @if (Model.ReferenceEntity != null)
                {
                    @Html.RenderBootstrapTabHeader("tab-reference", @T("Plugins.Misc.DynamicEntity.Reference"))
                }
            </ul>
            <div class="tab-content">
                @Html.RenderBootstrapTabContent("tab-info", @TabInfo(), true)
                @if (Model.ReferenceEntity != null)
                {
                    @Html.RenderBootstrapTabContent("tab-reference", @TabReference())
                }
            </div>
        </div>
    </div>
</div>

@{
    //custom tabs
    var eventMessage = new AdminTabStripCreated(this.Html, "fieldInfo-edit");
    EngineContext.Current.Resolve<IEventPublisher>().Publish(eventMessage);
    foreach (var eventBlock in eventMessage.BlocksToRender)
    {
        @eventBlock
    }
}

@*save selected tab name*@
<input type="hidden" id="selected-tab-name" name="selected-tab-name" value="@(Html.GetSelectedTabName())">

@helper TabInfo()
{
    <div class="content">
        <div class="form-horizontal">
            <div class="panel-group">
                <div class="panel panel-default panel-search">
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-12">
                                @Html.HiddenFor(m => m.Id)
                                <div class="form-group">
                                    <div class="col-md-3 col-sm-3">
                                        @Html.SDFLabelFor(m => m.SortNo)
                                    </div>
                                    <div class="col-md-9 col-sm-9">
                                        @Html.SDFEditorFor(m => m.SortNo)
                                        @Html.ValidationMessageFor(m => m.SortNo)
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-3 col-sm-3">
                                        @Html.SDFLabelFor(m => m.CodeName)
                                    </div>
                                    <div class="col-md-9 col-sm-9">
                                        @Html.SDFEditorFor(m => m.CodeName)
                                        @Html.ValidationMessageFor(m => m.CodeName)
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-3 col-sm-3">
                                        @Html.SDFLabelFor(m => m.Name)
                                    </div>
                                    <div class="col-md-9 col-sm-9">
                                        @Html.SDFEditorFor(m => m.Name)
                                        @Html.ValidationMessageFor(m => m.Name)
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-3 col-sm-3">
                                        @Html.SDFLabelFor(m => m.FieldType)
                                    </div>
                                    <div class="col-md-9 col-sm-9">
                                        @Html.SDFDropDownListFor(model => model.FieldType, EntityFieldTypeEnum.Bool.ToSelectList())
                                        @Html.ValidationMessageFor(m => m.FieldType)
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-3 col-sm-3">
                                        @Html.SDFLabelFor(m => m.FieldLength)
                                    </div>
                                    <div class="col-md-9 col-sm-9">
                                        @Html.SDFEditorFor(m => m.FieldLength)
                                        @Html.ValidationMessageFor(m => m.FieldLength)
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-3 col-sm-3">
                                        @Html.SDFLabelFor(m => m.ParamDirection)
                                    </div>
                                    <div class="col-md-9 col-sm-9">
                                        @Html.SDFDropDownListFor(model => model.ParamDirection, ParamDirectionEnum.Import.ToSelectList())
                                        @Html.ValidationMessageFor(m => m.ParamDirection)
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-3 col-sm-3">
                                        @Html.SDFLabelFor(m => m.DefaultValue)
                                    </div>
                                    <div class="col-md-9 col-sm-9">
                                        @Html.SDFEditorFor(model => model.DefaultValue)
                                        @Html.ValidationMessageFor(m => m.DefaultValue)
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="col-md-3 col-sm-3">
                                        @Html.SDFLabelFor(m => m.CreateTimeOnUtc)
                                    </div>
                                    <div class="col-md-9 col-sm-9">
                                        @Html.SDFEditorFor(m => m.CreateTimeOnUtc)
                                        @Html.ValidationMessageFor(m => m.CreateTimeOnUtc)
                                    </div>
                                </div>
                                <div style="display:none">
                                    @Html.HiddenFor(m => m.Delete)
                                    @Html.HiddenFor(m => m.HeaderId);
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
}

@helper TabReference()
{
    @Html.Partial("~/Plugins/SDF.Plugin.Misc.DynamicEntity/Views/DynamicEntity/_CreateOrUpdateEntity.cshtml", Model.ReferenceEntity.ToModel())
}
